<template>
  <div style="margin-top: 20px">
    <el-row>报表编号:{{ Code }}</el-row>
    <el-row :gutter="20">
      <el-col :span="12">
        <el-table
          :data="Params"
          :height="tableHeight"
          border
          fit
          highlight-current-row
          default-expand-all
          row-key="Id"
          :tree-props="{children: 'Children'}"
          style="width: 100%; margin-top: 20px"
        >
          <el-table-column label="请求参数">
            <el-table-column label="属性" prop="AttributeName" />
            <el-table-column label="名称" prop="Name" />
            <el-table-column label="类型">
              <template slot-scope="scope">
                {{ scope.row.Type | dictFilter(enums.reportParamTypeEnum) }}
              </template>
            </el-table-column>
          </el-table-column>
        </el-table>
      </el-col>
      <el-col :span="12">
        <el-table
          :data="Items"
          :height="tableHeight"
          border
          fit
          highlight-current-row
          default-expand-all
          row-key="Id"
          :tree-props="{children: 'Children'}"
          style="width: 100%; margin-top: 20px"
        >
          <el-table-column label="返回结果">
            <el-table-column label="属性" prop="AttributeName" />
            <el-table-column label="名称" prop="Name" />
            <el-table-column label="类型" prop="Type" />
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
  </div>
</template>

<script>

import apolloClient from '@/utils/graphql'
import gql from 'graphql-tag'
import reportParamTypeEnum from '@/enums/report/reportParamTypeEnum'

export default {
  name: 'ApiDoc',
  props: {
    // id
    id: {
      type: String,
      required: false
    }
  },
  data() {
    return {
      Items: [],
      Code: '',
      Params: [],
      enums: { reportParamTypeEnum }
    }
  },
  computed: {
    tableHeight() {
      return document.body.clientHeight - 200
    }
  },
  mounted() {
    this.getDetail()
  },
  methods: {

    getDetail() {
      apolloClient.query({
        fetchPolicy: 'network-only',
        query: gql`query ($reportId: String!) {
            reportApi(ReportId: $reportId){
                ResultStr
                RequestReportParams{
                    AttributeName
                    Name
                    Type
                }
                Report{
                    Code
                }
            }
        }`,
        variables: { reportId: this.id }
      }).then(response => {
        if (response.data) {
          if (response.data.reportApi) {
            this.Items = JSON.parse(response.data.reportApi.ResultStr)
            this.Code = response.data.reportApi.Report.Code
            this.Params = response.data.reportApi.RequestReportParams
          }
        } else {
          this.$notify.error(response.errors[0].message)
        }
      }).catch((err) => {
        this.$notify.error(err.message)
      })
    }

  }
}
</script>

<style scoped>
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.avatar-uploader .el-upload:hover {
    border-color: #409EFF;
}

.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
}

.avatar {
    width: 178px;
    height: 178px;
    display: block;
}
</style>
